package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.ProductUnitService;
import com.atguigu.spzx.model.common.Result;
import com.atguigu.spzx.model.entity.product.ProductUnit;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * title:
 * author: zgl
 * date: 2024/1/4
 * description：
 */
@RestController
@RequestMapping("/admin/base/productUnit")
@Tag(name = "商品单位管理模块")
public class ProductUnitController {
    @Autowired
    private ProductUnitService productUnitService;



    @GetMapping("/allProductUnit")
    @Operation(summary = "查询所有商品单位接口")
    public Result allProductUnit() {
      List<ProductUnit> unitList = productUnitService.allProductUnit();
        return Result.ok(unitList);
    }

    @GetMapping("/unitList/{pageNum}/{pageSize}")
    @Operation(summary = "商品单位分页查询")
    public Result getUnitList(
            @PathVariable Integer pageNum,
            @PathVariable Integer pageSize) {
        PageInfo<ProductUnit> pageInfo = productUnitService.getUnitList(pageNum, pageSize);
        return Result.ok(pageInfo);
    }

    @GetMapping("/getUnitById/{id}")
    @Operation(summary = "id查询商品单位接口")
    public Result getUnitById(@PathVariable Long id) {
        ProductUnit unit = productUnitService.getUnitById(id);
        return Result.ok(unit);
    }

    @DeleteMapping("/deletedUnit/{id}")
    @Operation(summary = "商品单位删除接口")
    public Result deletedUnit(@PathVariable Long id) {
        productUnitService.deletedUnit(id);
        return Result.ok();
    }

    @PutMapping("/updateUnit")
    @Operation(summary = "商品单位修改接口")
    public Result updateUnit(@RequestBody ProductUnit unit) {
        productUnitService.updateUnit(unit);
        return Result.ok();
    }

    @PostMapping("/saveUnit")
    @Operation(summary = "商品单位添加接口")
    public Result saveUnit(@RequestBody ProductUnit unit) {
        productUnitService.saveUnit(unit);
        return Result.ok();
    }

}
